//---------------------------------------------------------------------------

#ifndef CIISDBH
#define CIISDBH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Db.hpp>
#include <DBTables.hpp>
#include "CIISCommon.h"
#include <DB.hpp>

#include "CIISDBInit.h"

const int DBVer = 630;
const int PrgVer = 1201;

//---------------------------------------------------------------------------
class TCIISDBModule : public TDataModule
{
__published:	// IDE-managed Components
        TTable *TabProject;
        TTable *TabControllers;
        TTable *TabZones;
        TTable *TabSensors;
        TTable *TabRecordings;
        TTable *TabValues;
        TTable *TabValuesLPR;
				TTable *TabValuesDecay;
				TTable *TabPowerSupply;
        TTable *TabEventLog;
        TTable *TabNodes;
private:
		CIISServerMode ServerMode;
		String DBAlias;
		int InstalledDBVer;
		Boolean ForceUpdate;
		TTable *TabTmp;
		String EMess;
		String CurrDBDir;
		TCIISDBInitFrm *IFrm;
		TBatchMove *BMove;
		TLocateOptions NoOpts;

		void __fastcall CreateTabProject();
		void __fastcall CreateTabControllers();
		void __fastcall CreateTabZones();
		void __fastcall CreateTabNodes();
		void __fastcall CreateTabSensors();
		void __fastcall CreateTabPowerSupply();
		void __fastcall CreateTabRecordings();
		void __fastcall CreateTabValues();
		void __fastcall CreateTabValuesLPR();
		void __fastcall CreateTabValuesDecay();
		void __fastcall CreateTabEventLog();

		bool __fastcall CheckUpdateTabProject();
		bool __fastcall CheckUpdateTabControllers();
		bool __fastcall CheckUpdateTabZones();
		bool __fastcall CheckUpdateTabNodes();
		bool __fastcall CheckUpdateTabSensors();
		bool __fastcall CheckUpdateTabPowerSupply();
		bool __fastcall CheckUpdateTabRecordings();
		bool __fastcall CheckUpdateTabValues();
		bool __fastcall CheckUpdateTabValuesLPR();
		bool __fastcall CheckUpdateTabValuesDecay();
		bool __fastcall CheckUpdateTabEventLog();

		void __fastcall UpdateRecEnd();
		void __fastcall UpdateProgVer();

		bool __fastcall TmpFileExist( String FName );


public:
	void __fastcall Log(CIIEventType EvType, CIIEventCode EvCode,
                            CIIEventLevel EvLevel, String EvString,
                            Integer EvInt, double EvFloat);	// User declarations
                            
				__fastcall TCIISDBModule(TComponent* Owner);
				__fastcall ~TCIISDBModule();
	void __fastcall SetEventLogLevel(CIIEventType EvType, CIIEventLevel EvLevel);
	bool __fastcall InitCIISDB( String SetDBAlias, CIISServerMode SetServerMode );
	String __fastcall DBDir();
	bool __fastcall SetDBDir( String NewDir );
	TTable* __fastcall TabClone( TTable *TabSource, String TabName );
	bool __fastcall RecRunning();

};
//---------------------------------------------------------------------------
extern PACKAGE TCIISDBModule *CIISDBModule;
//---------------------------------------------------------------------------
#endif
